package com.mz.ozy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mz.ozy.R;
import com.mz.ozy.bean.RechargeRecordBean;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 */

public class RechargeRecordAdapter extends RecyclerView.Adapter<RechargeRecordAdapter.MyViewHolder> {


    private Context mContext;
    List<RechargeRecordBean.PageBean.PageItemsBean> mBeanList;

    public RechargeRecordAdapter(Context context, List<RechargeRecordBean.PageBean.PageItemsBean> mBeanList) {
        mContext = context;
        this.mBeanList = mBeanList;

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_recharge_record, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        /*b(金额数量),o(币状态0-充币中；1-成功；2-失败),f(时间),p(币种)*/
        RechargeRecordBean.PageBean.PageItemsBean bean = mBeanList.get(position);
        holder.tvNumber.setText(bean.getP());
        holder.tvDate.setText(bean.getF());
        final double number = Double.parseDouble(bean.getB());
        if (number > 0) {
            holder.tvStatus.setText("+" + number);
        } else {
            holder.tvStatus.setText(bean.getB());
        }
        int status = bean.getO();
        //0-充币中；1-成功；2-失败
        if (status == 0) {
            holder.tvCzType.setText(R.string.cb_status0);
            holder.tvCzType.setTextColor(mContext.getResources().getColor(R.color.c_c5c8d0));
        } else if (status == 1) {
            holder.tvCzType.setText(R.string.cb_status1);
            holder.tvCzType.setTextColor(mContext.getResources().getColor(R.color.c_519bff));
        } else if (status == 2) {
            holder.tvCzType.setText(R.string.cb_status2);
            holder.tvCzType.setTextColor(mContext.getResources().getColor(R.color.c_c5c8d0));
        }
    }

    @Override
    public int getItemCount() {
        return mBeanList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_number)
        TextView tvNumber;
        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.tv_status)
        TextView tvStatus;
        @BindView(R.id.tv_cz_type)
        TextView tvCzType;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }


    }


}
